package io.renren.modules.school.service.impl;

import io.renren.modules.school.dao.ProvinceAndCitiesDao;
import io.renren.modules.school.entity.ProvinceAndCitiesEntity;
import io.renren.modules.school.entity.TreeEntity;
import io.renren.modules.school.service.ProvinceAndCitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
@Transactional
public class ProvinceAndCitiesServiceImpl implements ProvinceAndCitiesService {

    @Autowired
    ProvinceAndCitiesDao provinceAndCitiesDao;

    @Override
    public List getProvinces(Map region) {
        String name= (String) region.get("name");
        return provinceAndCitiesDao.getProvince(name);
    }

    @Override
    public List getCities(Map region) {
        String name= (String) region.get("name");
        List<String> list=provinceAndCitiesDao.getCities(name);
        List<String> l=new ArrayList<>();
        for(String s:list){
            String[] sl=s.split(",");
            l.addAll(Arrays.asList(sl));
        }
        return l;
    }

    @Override
    public List<TreeEntity> getAreaList() {
        return provinceAndCitiesDao.getAreaList();
    }

    @Override
    public List<ProvinceAndCitiesEntity> getProvincesList() {
        return provinceAndCitiesDao.getProvincesList();
    }

}
